/**
 * 
 */
package com.shunwang.locks;

/**
 * @author ljw
 *
 */
public class ThreadTest implements Runnable {

	private Thread blinker;
	
	public void start() {
        blinker = new Thread(this);
        blinker.start();
    }

    public void stop() {
        blinker.stop();  // UNSAFE!
    }
    
    public void stop(Throwable t){
    	blinker.stop(t);
    }
	@Override
	public void run() {
		Thread thisThread = Thread.currentThread();
        while (true) {
            try {
            	synchronized (ThreadTest.class) {
            		thisThread.sleep(1000*2);
				}
            } catch (InterruptedException e){
            	System.out.println(getThreadName()+" over...");
            } catch(ThreadDeath death){
            	System.out.println(getThreadName()+" dead ");
            	return;
            } catch(Throwable t){
            	System.out.println(t);
            	return;
            }
            System.out.println(getThreadName()+" running");
        }
	}
	
	public String getThreadName(){
    	return Thread.currentThread().getName();
    }
	
	public static void main(String[] args){
		ThreadTest t1 = new ThreadTest();
		t1.start();
		for(int i=0;i<3;i++){
			ThreadTest t = new ThreadTest();
			t.start();
		}
		t1.stop();
	}

}
